﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;

namespace IHISCETeim.BLL
{
    /// <summary>
    /// 1.应收账款主表(FTradeReceivables)
    /// </summary>
    public class FTradeReceivablesController : BaseController
    {
        /// <summary>
        /// 添加应收账款
        /// </summary>
        /// <param name="objReceivables">应收账款主表(FTradeReceivables)</param>
        /// <param name="objSalesType">应收帐款销售类型更改记录表</param>
        /// <param name="listAgeDetails">应收账款帐龄明细表(FTradeAgeDetail)多个</param>
        /// <returns>
        /// 返回空表示成功,否则返回失败信息
        /// </returns>
        public static string Add(FTradeReceivablesInfo objReceivables, FTradeSalesTypeInfo objSalesType, List<FTradeAgeDetailInfo> listAgeDetails)
        {
            return FTradeReceivablesDAL.Add(objReceivables, objSalesType, listAgeDetails);
        }
        /// <summary>
        /// 删除应收帐款记录.
        ///1.需判断　7.冲帐记录(FTradeBalance)　　是否有　状态　为正常　的记录,如果有,则提示不能删除,只能先调帐再删除
        ///2.删除　机器维保费收入记录(FTradeUpKeep)
        ///3.删除　3.应收账款帐龄明细表(FTradeAgeDetail)
        ///4.删除　2.应收帐款销售类型更改记录表(FTradeSalesType)
        ///5.删除　1.应收账款主表(FTradeReceivables)
        /// </summary>
        /// <param name="FTradeID"></param>
        /// <returns></returns>
        public static string Delete(int FTradeID)
        {
            return FTradeReceivablesDAL.Delete(FTradeID);
        }
        /// <summary>
        /// 将返还利息 正常(未结算) =>正常(已结算)
        /// </summary>
        /// <param name="FTradeID"></param>
        /// <returns></returns>
        public static bool UpdateFanHuanLiXiState(int FTradeID,string FanHuanLiXiState)
        {
            return FTradeReceivablesDAL.UpdateFanHuanLiXiState(FTradeID, FanHuanLiXiState);
        }
        public static FTradeReceivablesInfo GetByFTradeID(int FTradeID)
        {
            return CBO.FillObject<FTradeReceivablesInfo>( FTradeReceivablesDAL.GetByFTradeID(FTradeID));
        }

        public static DataTableCollection GetPagination(string WhereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            return FTradeReceivablesDAL.GetPagination(WhereSql, PageIndex, PageSize, Sort, ref  TotalCount);
        }
        /// <summary>
        /// 应收帐款基本信息的更新
        /// 如开票信息,终端信息,及基本信息,
        /// 更改销售类型不在此过程操作
        /// </summary>
        public static bool Update(FTradeReceivablesInfo obj)
        {
            return FTradeReceivablesDAL.Update(obj);
        }

        /// <summary>
        /// 判断应收账款是否可删除,是否可变更销售类型
        /// </summary>
        /// <param name="FTradeID"></param>
        /// <returns></returns>
        public static string CheckCanChange(int FTradeID)
        {
            return FTradeReceivablesDAL.CheckCanChange(FTradeID);
        }

        /// <summary>
        /// 添加或修改时,判断机号是否被使用,如果被使用则返回 错误信息
        /// </summary>
        /// <param name="JiHao"></param>
        /// <param name="FTradeID"></param>
        /// <returns></returns>
        public static string CheckJiHao(string JiHao, int FTradeID)
        {
            return FTradeReceivablesDAL.CheckJiHao(JiHao, FTradeID);
        }
        /// <summary>
        /// 添加导入数据
        /// </summary>
        /// <param name="objReceivables">修改原有</param>
        /// <param name="objSalesType">销售类型</param>
        /// <param name="listAgeDetails">帐领</param>
        /// <returns></returns>
        public static string AddImport(FTradeReceivablesInfo objReceivables, FTradeSalesTypeInfo objSalesType, List<FTradeAgeDetailInfo> listAgeDetails)
        {
            return FTradeReceivablesDAL.AddImport(objReceivables, objSalesType, listAgeDetails);
        }

        /// <summary>
        /// 获取原数据源的 的冲帐记录,并自动生成相应的收款记录
        /// </summary>
        /// <param name="FTradeID_Fu">原数据源ID</param>
        /// <param name="RemarkTag">新收款记录标题及备注 说明</param>
        /// <returns></returns>
        private static Dictionary<int, FTradeCatheringInfo> GetOldBalanceList(int FTradeID_Fu,string RemarkTag)
        {
            Dictionary<int, FTradeCatheringInfo> returnDic = new Dictionary<int, FTradeCatheringInfo>();

            FTradeReceivablesInfo objRec = FTradeReceivablesController.GetByFTradeID(FTradeID_Fu);

            //1.获取原冲帐记录
            string sqlwhere = string.Format(" FTradeID={0} ", FTradeID_Fu);
            DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int FbalanceId = Convert.ToInt32(dr["FbalanceId"]);
                    FTradeCatheringInfo objCat = new FTradeCatheringInfo();
                    //机号 RemarkTag _ 原 ShowTitle 冲帐款 
                    objCat.FCTitle = string.Format("{0} {1} 原 {2} 冲帐款", objRec.JiHao, RemarkTag, dr["ShowTitle"]);
                  //  objCat.FCTitle = string.Format("{0}原{1}_{2}{3}", DateTime.Now.ToString("yyyy-MM-dd"), objRec.JingXiaoShang, objRec.JiHao + RemarkTag, Convert.ToDecimal(dr["AdjustingMoney"]));
                    objCat.ShoukuanRiQi = Convert.ToDateTime(dr["ShoukuanRiQi"]); ;
                    objCat.JingXiaoShang = objRec.JingXiaoShang;
                    objCat.JinE = Convert.ToDecimal(dr["AdjustingMoney"]);
                    objCat.KuanXiangLeiXing = dr["KuanXiangLeiXing"].ToString();
                    objCat.oldKuanXiangLeiXing = dr["KuanXiangLeiXing"].ToString();

                    objCat.RealName = OUserController.CurrentUser.RealName;
                    objCat.IsAdjustable = false;
                    objCat.State = "未冲完";
                    objCat.Remark = objRec.JiHao + RemarkTag;
                    objCat.SourceTag = "系统";

                    returnDic.Add(FbalanceId, objCat);
                }
            }
            else
            {
                //没有冲帐记录,并是2013年前已付完的
                if (objRec.JiQiState == "正常" && objRec.WeiShouKuanXiang == 0m && objRec.XiaoShouShiJian.Year < 2013)
                {
                   // BalanceMoneys = objRec.YiShouKuanXiang;
                    int FbalanceId =0;
                    FTradeCatheringInfo objCat = new FTradeCatheringInfo();
                    objCat.FCTitle = string.Format("{0} {1}", objRec.JiHao, RemarkTag);
                    //objCat.FCTitle = string.Format("{0}{1}_{2}{3}", DateTime.Now.ToString("yyyy-MM-dd"), objRec.JingXiaoShang, objRec.JiHao + RemarkTag, objRec.YiShouKuanXiang);
                    objCat.ShoukuanRiQi =DateTime.Now;
                    objCat.JingXiaoShang = objRec.JingXiaoShang;
                    objCat.JinE = objRec.YiShouKuanXiang;
                    objCat.KuanXiangLeiXing = "调帐";
                    objCat.oldKuanXiangLeiXing = "调帐";

                    objCat.RealName = OUserController.CurrentUser.RealName;
                    objCat.IsAdjustable = false;
                    objCat.State = "未冲完";
                    objCat.Remark = objRec.JiHao + RemarkTag;
                    objCat.SourceTag = "系统";

                    returnDic.Add(FbalanceId, objCat);
                }
            }


            return returnDic;
        }
      
        /// <summary>
        /// 退机
        /// </summary>
        /// <param name="objNewFu">退机后负记录的信息</param>
        /// <param name="FbalanceIds">原冲帐ID</param>
        /// <param name="objCat">回收原冲帐信息的收款记录信息</param>
        /// <returns>
        /// 大于0表示退机成功，并需要处理冲帐
        /// 等于0表示退机成功，但无法处理冲帐
        /// 小于表示退机失败
        /// </returns>
        public static int AddTuiJi(FTradeReceivablesInfo objNewFu, FTradeReceivablesInfo objOld,FTradeAgeDetailInfo objDetail)
        {
            #region 
            ////1.获取原冲帐记录
            //string sqlwhere = string.Format(" FTradeID={0} ", objNewFu.FTradeID);
            //DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);

            //FTradeCatheringInfo objCat = new FTradeCatheringInfo();
            //List<int> FbalanceIds = new List<int>();
            //Decimal BalanceMoneys = 0m;
            ////2.调帐后新的的收款记录
            //FTradeReceivablesInfo objRec = FTradeReceivablesController.GetByFTradeID(objNewFu.FTradeID);
            //if (dt.Rows.Count > 0)
            //{  
            //    foreach (DataRow dr in dt.Rows)
            //    {
            //        FbalanceIds.Add(Convert.ToInt32(dr["FbalanceId"]));
            //        BalanceMoneys += Convert.ToDecimal(dr["AdjustingMoney"]);//总冲帐款
            //    }               
            //}
            //else
            //{
            //    //没有冲帐记录,并是2013年前已付完的
            //    if (objRec.JiQiState == "正常" && objRec.WeiShouKuanXiang == 0m && objRec.XiaoShouShiJian.Year < 2013)
            //    {
            //        BalanceMoneys = objRec.YiShouKuanXiang;
            //    }
            //}

            //// FTradeCatheringInfo objCat = new FTradeCatheringInfo();
            //objCat.FCTitle = string.Format("{0}{1}_{2}{3}", DateTime.Now.ToString("yyyy-MM-dd"), objRec.JingXiaoShang, objRec.JiHao + "退机调帐款", BalanceMoneys);
            //objCat.ShoukuanRiQi = DateTime.Now;
            //objCat.JingXiaoShang = objRec.JingXiaoShang;
            //objCat.JinE = BalanceMoneys;
            //objCat.KuanXiangLeiXing = "调帐";
            //objCat.oldKuanXiangLeiXing = "调帐";

            //objCat.RealName = OUserController.CurrentUser.RealName;
            //objCat.IsAdjustable = false;
            //objCat.State = "未冲完";
            //objCat.Remark = objRec.JiHao + "退机调帐款";
            //objCat.SourceTag = "系统";
            #endregion

            Dictionary<int, FTradeCatheringInfo> OldBalanceList = GetOldBalanceList(objNewFu.FTradeID, "退机调帐款");

            objNewFu.JiQiState = "退机";
            objNewFu.CreateDate = DateTime.Now;



            return FTradeReceivablesDAL.AddTuiJi(objNewFu, OldBalanceList, objOld, objDetail);
        }

        /// <summary>
        /// 换机
        /// </summary>
        /// <param name="objNewFu">旧记录负的信息</param>
        /// <param name="objNew">新机信息</param>
        /// <returns></returns>
        public static int AddHuanJi(FTradeReceivablesInfo objNewFu, FTradeReceivablesInfo objNew, FTradeSalesTypeInfo objSalesType, List<FTradeAgeDetailInfo> listAgeDetails)
        {
            ////1.获取原冲帐记录
            //string sqlwhere = string.Format(" FTradeID={0} ", objNewFu.FTradeID);
            //DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);

            //FTradeCatheringInfo objCat = new FTradeCatheringInfo();
            //List<int> FbalanceIds = new List<int>();
            //Decimal BalanceMoneys = 0m;
            ////2.调帐后新的的收款记录
            //FTradeReceivablesInfo objRec = FTradeReceivablesController.GetByFTradeID(objNewFu.FTradeID);

            //if (dt.Rows.Count > 0)
            //{               
            //    foreach (DataRow dr in dt.Rows)
            //    {
            //        FbalanceIds.Add(Convert.ToInt32(dr["FbalanceId"]));
            //        BalanceMoneys += Convert.ToDecimal(dr["AdjustingMoney"]);//总冲帐款
            //    }
            
            //}
            //else
            //{
            //    //没有冲帐记录,并是2013年前已付完的
            //    if (objRec.JiQiState == "正常" && objRec.WeiShouKuanXiang == 0m && objRec.XiaoShouShiJian.Year < 2013)
            //    {
            //        BalanceMoneys = objRec.YiShouKuanXiang;
            //    }
            //}
            //// FTradeCatheringInfo objCat = new FTradeCatheringInfo();
            //objCat.FCTitle = string.Format("{0}{1}_{2}{3}", DateTime.Now.ToString("yyyy-MM-dd"), objRec.JingXiaoShang, objRec.JiHao + "换机调帐款", BalanceMoneys);
            //objCat.ShoukuanRiQi = DateTime.Now;
            //objCat.JingXiaoShang = objRec.JingXiaoShang;
            //objCat.JinE = BalanceMoneys;
            //objCat.KuanXiangLeiXing = "调帐";
            //objCat.oldKuanXiangLeiXing = "调帐";
            //objCat.RealName = OUserController.CurrentUser.RealName;
            //objCat.IsAdjustable = false;
            //objCat.State = "未冲完";
            //objCat.Remark = objRec.JiHao + "换机调帐款";
            //objCat.SourceTag = "系统";
            Dictionary<int, FTradeCatheringInfo> OldBalanceList = GetOldBalanceList(objNewFu.FTradeID, "换机调帐款");

            objNewFu.JiQiState = "换机";
            objNewFu.CreateDate = DateTime.Now;
            return FTradeReceivablesDAL.AddHuanJi(OldBalanceList, objNewFu, objNew, objSalesType, listAgeDetails);
        }
        /// <summary>
        /// 改分期
        /// </summary>
        /// <param name="objNewFu"></param>
        /// <param name="objTrade"></param>
        /// <param name="objSalesType"></param>
        /// <param name="listAgeDetails"></param>
        /// <returns></returns>
        public static int UpdateSaleType(FTradeReceivablesInfo objNewFu, FTradeReceivablesInfo objTrade, FTradeSalesTypeInfo objSalesType, List<FTradeAgeDetailInfo> listAgeDetails)
        {         
            ////1.获取原冲帐记录
            //string sqlwhere = string.Format(" FTradeID={0} ", objNewFu.FTradeID);
            //DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);

            //FTradeCatheringInfo objCat = new FTradeCatheringInfo();
            //List<int> FbalanceIds = new List<int>();
            //Decimal BalanceMoneys = 0m;
            ////2.调帐后新的的收款记录
            //FTradeReceivablesInfo objRec = FTradeReceivablesController.GetByFTradeID(objNewFu.FTradeID);

            //if (dt.Rows.Count > 0)
            //{  
            //    foreach (DataRow dr in dt.Rows)
            //    {
            //        FbalanceIds.Add(Convert.ToInt32(dr["FbalanceId"]));
            //        BalanceMoneys += Convert.ToDecimal(dr["AdjustingMoney"]);//总冲帐款
            //    }               
            //}
            //else
            //{
            //    //没有冲帐记录,并是2013年前已付完的
            //    if (objRec.JiQiState == "正常" && objRec.WeiShouKuanXiang == 0m && objRec.XiaoShouShiJian.Year < 2013)
            //    {
            //        BalanceMoneys = objRec.YiShouKuanXiang;
            //    }
            //}
            //// FTradeCatheringInfo objCat = new FTradeCatheringInfo();
            //objCat.FCTitle = string.Format("{0}{1}_{2}{3}", DateTime.Now.ToString("yyyy-MM-dd"), objRec.JingXiaoShang, objRec.JiHao + "改分期调帐款", BalanceMoneys); //objRec.JiHao + "改分期调帐款";
            //objCat.ShoukuanRiQi = DateTime.Now;
            //objCat.JingXiaoShang = objRec.JingXiaoShang;
            //objCat.JinE = BalanceMoneys;
            //objCat.KuanXiangLeiXing = "调帐";
            //objCat.oldKuanXiangLeiXing = "调帐";
            //objCat.RealName = OUserController.CurrentUser.RealName;
            //objCat.IsAdjustable = false;
            //objCat.State = "未冲完";
            //objCat.Remark = objRec.JiHao + "改分期调帐款";
            //objCat.SourceTag = "系统";
            Dictionary<int, FTradeCatheringInfo> OldBalanceList = GetOldBalanceList(objNewFu.FTradeID, "改分期调帐款");

            objNewFu.JiQiState = "改分期";
            objNewFu.CreateDate = DateTime.Now;

            return FTradeReceivablesDAL.AddHuanJi(OldBalanceList, objNewFu, objTrade, objSalesType, listAgeDetails);
        }

        /// <summary>
        /// 改经销商
        /// </summary>
        /// <param name="objNewFu">旧记录负的信息</param>
        /// <param name="objNew">新机信息</param>
        /// <returns></returns>
        public static int ChangeAgent(FTradeReceivablesInfo objNewFu, FTradeReceivablesInfo objNew, FTradeSalesTypeInfo objSalesType, List<FTradeAgeDetailInfo> listAgeDetails)
        {
            ////1.获取原冲帐记录
            //string sqlwhere = string.Format(" FTradeID={0} ", objNewFu.FTradeID);
            //DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);

            //FTradeCatheringInfo objCat = new FTradeCatheringInfo();
            //List<int> FbalanceIds = new List<int>();

            //Decimal BalanceMoneys = 0m;
            //FTradeReceivablesInfo objRec = FTradeReceivablesController.GetByFTradeID(objNewFu.FTradeID);

            //if (dt.Rows.Count > 0)
            //{               
            //    foreach (DataRow dr in dt.Rows)
            //    {
            //        FbalanceIds.Add(Convert.ToInt32(dr["FbalanceId"]));
            //        BalanceMoneys += Convert.ToDecimal(dr["AdjustingMoney"]);//总冲帐款
            //    }
               
            //}
            //else
            //{
            //    //没有冲帐记录,并是2013年前已付完的
            //    if (objRec.JiQiState == "正常" && objRec.WeiShouKuanXiang == 0m && objRec.XiaoShouShiJian.Year < 2013)
            //    {
            //        BalanceMoneys = objRec.YiShouKuanXiang;
            //    }
            //}
            ////2.调帐后新的的收款记录 
            //objCat.FCTitle = DateTime.Now.ToString("yyyy-MM-dd") + "_" + objRec.JiHao + "改经销商调帐款" + BalanceMoneys.ToString("N2");
            //objCat.ShoukuanRiQi = DateTime.Now;
            //objCat.JingXiaoShang = objRec.JingXiaoShang;
            //objCat.JinE = BalanceMoneys;
            //objCat.KuanXiangLeiXing = "调帐";
            //objCat.oldKuanXiangLeiXing = "调帐";
            //objCat.RealName = OUserController.CurrentUser.RealName;
            //objCat.IsAdjustable = false;
            //objCat.State = "未冲完";
            //objCat.Remark = objRec.JiHao + "改经销商调帐款";
            //objCat.SourceTag = "系统";

            Dictionary<int, FTradeCatheringInfo> OldBalanceList = GetOldBalanceList(objNewFu.FTradeID, "改经销商调帐款");

            objNewFu.JiQiState = "改经销商";
            objNewFu.CreateDate = DateTime.Now;
            return FTradeReceivablesDAL.AddHuanJi(OldBalanceList, objNewFu, objNew, objSalesType, listAgeDetails);
        }

        /// <summary>
        /// 变更合同信息
        /// </summary>
        /// <param name="objNewFu"></param>
        /// <param name="objSalesType"></param>
        /// <param name="listAgeDetails"></param>
        /// <returns></returns>
        public static int AddChangeHeTong(FTradeReceivablesInfo objNewFu,FTradeSalesTypeInfo objSalesType, List<FTradeAgeDetailInfo> listAgeDetails)
        {
            ////1.获取原冲帐记录
            //string sqlwhere = string.Format(" FTradeID={0} ", objNewFu.FTradeID);
            //DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);
            //FTradeCatheringInfo objCat = new FTradeCatheringInfo();
            //List<int> FbalanceIds = new List<int>();
            //FTradeReceivablesInfo obj2013TR = FTradeReceivablesController.GetByFTradeID(objNewFu.FTradeID);//用于判断是否是2013前已付完的记录
            ////2013 10 29 修改
            //Decimal BalanceMoneys = 0m;
            //if (dt.Rows.Count > 0)
            //{               
            //    foreach (DataRow dr in dt.Rows)
            //    {
            //        FbalanceIds.Add(Convert.ToInt32(dr["FbalanceId"]));
            //        BalanceMoneys += Convert.ToDecimal(dr["AdjustingMoney"]);//总冲帐款
            //    }
            //}
            //else
            //{ 
            //    //没有冲帐记录,并是2013年前已付完的
            //    if (obj2013TR.JiQiState == "正常" && obj2013TR.WeiShouKuanXiang == 0m && obj2013TR.XiaoShouShiJian.Year < 2013)
            //    {
            //        BalanceMoneys = obj2013TR.YiShouKuanXiang;
            //    }
            //}
            ////2.调帐后新的的收款记录    
            //objCat.FCTitle = string.Format("{0}{1}_{2}{3}", DateTime.Now.ToString("yyyy-MM-dd"), obj2013TR.JingXiaoShang, obj2013TR.JiHao + "变更合同条款调帐款", BalanceMoneys);
            //objCat.ShoukuanRiQi = DateTime.Now;
            //objCat.JingXiaoShang = obj2013TR.JingXiaoShang;
            //objCat.JinE = BalanceMoneys;
            //objCat.KuanXiangLeiXing = "调帐";
            //objCat.oldKuanXiangLeiXing = "调帐";
            //objCat.RealName = OUserController.CurrentUser.RealName;
            //objCat.IsAdjustable = false;
            //objCat.State = "未冲完";
            //objCat.Remark = obj2013TR.JiHao + "变更合同条款调帐款";
            //objCat.SourceTag = "系统";

            Dictionary<int, FTradeCatheringInfo> OldBalanceList = GetOldBalanceList(objNewFu.FTradeID, "变更合同条款调帐款");

            objNewFu.JiQiState = "正常";
            objNewFu.CreateDate = DateTime.Now;
            return FTradeReceivablesDAL.AddChangeHeTong(OldBalanceList, objNewFu, objSalesType, listAgeDetails);
        }
         /// <summary>
        /// 处理调整GPS费用
        /// </summary>
        /// <param name="FTradeID"></param>
        /// <param name="FTradeAgeId">最后一条ID</param>
        /// <param name="NewGPSFeiYong"></param>
        /// <param name="deleteJinE"></param>
        /// <param name="State"></param>
        /// <param name="Remark"></param>
        /// <returns></returns>
        public static int UpdateGPSFeiYong(int FTradeID, decimal NewGPSFeiYong)
        {

            decimal weekreportJinE = 0m;
            decimal adGPSFeiYong = 0m;
            ///本次调GPS费用
            decimal deleteJinE=0m; 
            string State=""; 
            string Remark;
            ///最后一条未收的金额
            decimal lastAgeWeiShou = 0m;//

            FTradeReceivablesInfo objFT = GetByFTradeID(FTradeID);
            FTradeAgeDetailInfo objFA = FTradeAgeDetailController.GetLastByFTradeID(FTradeID);
           /// FTradeCatheringInfo objCatLast=FTradeCatheringController.GetById(objFA.f
            FTradeCatheringInfo objCat = new FTradeCatheringInfo();
            objCat.JinE = 0M;
            adGPSFeiYong = objFT.GPSFeiYong - NewGPSFeiYong;

            lastAgeWeiShou = objFA.JinE - objFA.YiChongJinE;
            deleteJinE = objFT.GPSFeiYong - NewGPSFeiYong;
            weekreportJinE = objFT.GPSFeiYong - NewGPSFeiYong;
            Remark = string.Format("GPS调整费用{0}元.原应付{1},调整后应付{2}", adGPSFeiYong, objFA.JinE, objFA.JinE - adGPSFeiYong);
            if (lastAgeWeiShou > deleteJinE)
            {
                State = "正常";
                deleteJinE = 0;
            }
            else if (lastAgeWeiShou == deleteJinE)
            {
                State = "已冲帐";
                deleteJinE = 0;
            }
            else if (lastAgeWeiShou < deleteJinE)
            {
                deleteJinE = deleteJinE - lastAgeWeiShou;
                State = "已冲帐";
                //需处理多出的帐款
                objCat.FCTitle = string.Format("{0}{1}_{2}{3}", DateTime.Now.ToString("yyyy-MM-dd"), objFT.JingXiaoShang, objFT.JiHao + "调整GPS费用", deleteJinE);
                objCat.ShoukuanRiQi = DateTime.Now;
                objCat.JingXiaoShang = objFT.JingXiaoShang;
                objCat.JinE = deleteJinE;
                objCat.KuanXiangLeiXing = "其他";
                objCat.oldKuanXiangLeiXing = "其他";
                objCat.RealName = OUserController.CurrentUser.RealName;
                objCat.IsAdjustable = false;
                objCat.State = "未冲完";
                objCat.Remark = objFT.JiHao + "调整GPS费用";
                objCat.SourceTag = "系统";
            }

            return FTradeReceivablesDAL.UpdateGPSFeiYong(FTradeID, objFA.FTradeAgeId, NewGPSFeiYong, deleteJinE, State, Remark, objCat, weekreportJinE);

        }
        /*
         导出周报
         */
        public static DataTableCollection FTradeReceivablesHistoryGetPagination(string WhereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            return FTradeReceivablesDAL.FTradeReceivablesHistoryGetPagination(WhereSql, PageIndex, PageSize, Sort, ref  TotalCount);
        }

        /// <summary>
        /// 获取透视表数据
        /// </summary>
        /// <param name="WhereSql"></param>
        /// <returns></returns>
        public static DataTableCollection GetPivotTable(string WhereSql)
        {
            return FTradeReceivablesDAL.GetPivotTable(WhereSql);
        }
        /// <summary>
        /// 经销商机型销售明细表
        /// </summary>
        /// <param name="WhereSql"></param>
        /// <returns></returns>
        public static DataTableCollection GetPivotTable2(string WhereSql)
        {
            return FTradeReceivablesDAL.GetPivotTable2(WhereSql);
        }
        /// <summary>
        /// 更新合同原件是否收到
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static Boolean UpdateYuanJian(FTradeReceivablesInfo obj)
        {
            return FTradeReceivablesDAL.UpdateYuanJian(obj);
        }
        /// <summary>
        
    }
}
